package com.zzy.jwt.service;

import com.zzy.jwt.mapper.UserMapper;
import com.zzy.jwt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author Lucas-zhang
 * @description TODO
 * @date 2022-03-22 17:00
 */
@Service
public class UserService implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userMapper.findUserByUsername(username);
        if (user == null) {
            throw new UsernameNotFoundException("User: " + username + " not exist!");
        }

        return user;
    }
}
